<?php
	class Form extends BaseLogic{
		private $tabName2;
		function __construct(){
			parent::__construct($showError=TRUE);
			$this->tabName=TAB_PREFIX."form";
			$this->tabName2=TAB_PREFIX."user";
		}
		
		function addForm($post){
			$post["ctime"]=time();
			if($this->add($post)){
				$this->messList[] = "订单生成成功.";
				return true;
			}else{
				$this->messList[] = "添加订单失败.";
				return false;
			}
		}
		
		function modForm($postList){
			if($this->mod($postList)){
				$this->messList[] = "订单修改成功.";
				return true;
			}else{
				$this->messList[] = "订单修改失败.";
				return false;
			}
		}
		
		function delForm($uid,$pid=false){
			if(is_array($uid)){
				$tmp = "IN (" . join(",", $uid) . ")";
			}else{
				$tmp = "= $uid";
			}
			if($pid){
				$sql = "DELETE FROM {$this->tabName} WHERE pid " . $tmp ;
			}else{
				$sql = "DELETE FROM {$this->tabName} WHERE uid " . $tmp ;
			}
			$result=$this->mysqli->query($sql);
			
			if($result && $this->mysqli->affected_rows >0){
				return true;
			}else{
				return false;
			}
		}
		
		function getForm($pid, $offset, $num){
//			$sql="SELECT f.fid,u.username username,f.ctime ctime, c.content content, c.cmt cmt, c.support support, c.oppose oppose FROM {$this->tabName} c, {$this->tab2Name} u WHERE c.uid=u.id AND c.aid={$aid} ORDER BY c.id DESC LIMIT $offset, $num";
			$result=$this->mysqli->query($sql);
			while($row=$result->fetch_assoc()) {
				$data[]=$row;
			}
			return $data;
		}
		
		function getRowTotal($pid){
			$result=$this->mysqli->query("SELECT * FROM {$this->tabName} WHERE pid={$pid}");
			return $result->num_rows;
		}
		
		function getAllForm(){
//			$sql = "SELECT fid, fname, price FROM {$this->tabName} ORDER BY pid ASC LIMIT $offset, $num";
			$result=$this->mysqli->query($sql);
			while($row=$result->fetch_assoc()){
				$data[]=$row;
			}
			return $data;
		}
		
		function validateForm(){
			
		}
	}
?>